package com.pcjavanet.collect.mes.dao;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.pcjavanet.collect.mes.to.ChartData;
import com.pcjavanet.collect.mes.to.ContinuousData;
import com.pcjavanet.collect.mes.to.ContinuousDataDetail;

/**
 * interface ContinuousDataDao.
 * @version 4.0
 * @author jerry_xia
 * @date January 12,2012
 */
public interface ContinuousDataDao {
	
	/**
	 * get max data id by monitor id.
	 * @param monitorId -int
	 * @return dataId - int
	 * @throws DataAccessException
	 */
	public int getMaxDataKeyByMonitorId(final int monitorId) throws DataAccessException;
	
	/**
	 * get count continuous data by monitor id.
	 * @param monitorId -int
	 * @return count - int
	 * @throws DataAccessException
	 */
	public int getCountContinuousDataByMonitorId(final int monitorId) throws DataAccessException;
	
	/**
	 * get current timestamp from database.
	 * @return  timestamp - String.
	 * @throws DataAccessException
	 */
	public String getDatabaseCurrentTimeStamp() throws DataAccessException;
	
	/**
	 * get last continuous data by monitor id.
	 * @param monitorId -int
	 * @return ContinuousData - continuousData
	 * @throws DataAccessException
	 */
	public ContinuousData getLastContinuousDataByMonitorId(final int monitorId) throws DataAccessException;
	
	/**
	 * get continuous data by data id.
	 * @param dataId -int
	 * @return ContinuousData - continuousData
	 * @throws DataAccessException
	 */
	public ContinuousData getContinuousDataByDataId(final int dataId) throws DataAccessException;
	
	/**
	* get fourteen continuous datas before data key by monitor id and chart type and revision.
	* @param monitorId -int
	* @param chartType -String
	* @param revision -int
	* @param dataKey -int
	* @throws DataAccessException
	*/
	public List<ContinuousData> getFourteenContinuousDatasBeforeDataKey(final int monitorId, final String chartType, final int revision,
		final int dataKey) throws DataAccessException;
	
	/**
	* get continuous datas by monitor id and date .
	* @param monitorId -int
	* @param startDate -Date
	* @param endDate -Date
	* @param dataStatus -int
	* @return List<ContinuousData> - continuousDataList
	* @throws DataAccessException
	*/
	public List<ContinuousData> getContinuousDatasByMonitorNameAndDate(final int monitorId, final long startDate, final long endDate, final int dataStatus) throws DataAccessException;
	
	/**
	*  get current page continuous datas by monitor id and date .
	* @param start -int
	* @param limit -int
	* @param monitorId -int
	* @param startDate -Date
	* @param endDate -Date
	* @param dataStatus -int
	* @return List<ContinuousData> - continuousDataList
	* @throws DataAccessException
	*/
	public List<ContinuousData> getCurrentPageContinuousDatasByMonitorNameAndDate(int start,int limit,final int monitorId, final long startDate, final long endDate, final int dataStatus) throws DataAccessException;
	
	/**
	* add continuous data.
	* @param continuousData -ContinuousData
	* @return result -int
	* @throws DataAccessException
	*/
	public int addContinuousData(final ContinuousData continuousData) throws DataAccessException ;
	
	/**
	* add continuous data include date.
	* @param continuousData -ContinuousData
	* @return result -int
	* @throws DataAccessException
	*/
	public int addContinuousDataIncludeDate(final ContinuousData continuousData) throws DataAccessException;
	
	/**
	* add continuous data detail.
	* @param continuousDataDetail -List<ContinuousDataDetail>
	* @return result -int
	* @throws DataAccessException
	*/
	public int addContinuousDataDetail(final List<ContinuousDataDetail> continuousDataDetailList) throws DataAccessException;
	
	/**
	* update continuous data.
	* @param continuousData -ContinuousData
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateContinuousData(final ContinuousData continuousData) throws DataAccessException;
	
	/**
	* update data status .
	* @param dataId -int
	* @param dataStatus -int
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateDataStatus(final int dataId,final int dataStatus) throws DataAccessException;
	
	/**
	* add chart data.
	* @param chartData -ChartData
	* @return result -int
	* @throws DataAccessException
	*/
	public int addChartData(final ChartData chartData) throws DataAccessException;
	
	/**
	* add continuous data detail.
	* @param continuousDataDetail -ContinuousDataDetail
	* @return result -int
	* @throws DataAccessException
	*/
	public int addContinuousDataDetail(final ContinuousDataDetail continuousDataDetail) throws DataAccessException;
	
	/**
	* update continuous data detail.
	* @param continuousDataDetail -ContinuousDataDetail
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateContinuousDataDetail(final ContinuousDataDetail continuousDataDetail) throws DataAccessException ;
	
	/**
	 * get continuous data detail by data id.
	 * @param dataId -int
	 * @return List<ContinuousDataDetail> - continuousDataDetailList
	 * @throws DataAccessException
	 */
	public List<ContinuousDataDetail> getContinuousDataDetailByDataId(final int dataId) throws DataAccessException;
	
	/**
	 * get cpk chart id by monitor id and revision.
	 * @param monitorId -int
	 * @param revision -int
	 * @return chartId - int
	 * @throws DataAccessException
	 */
	public int getCpkChartIdByMonitorIdAndRevision(final int monitorId, final int revision) throws DataAccessException;
	
	/**
	* get chart id by data key and chart type.
	* @param dataKey -int
	* @param chartType -String
	* @throws DataAccessException
	*/
	public int getChartIdByDataKeyAndChartType(final int dataKey, final String chartType) throws DataAccessException;
	
	/**
	* is exist by monitor id and create date.
	* @param monitorId -int
	* @param createDate -Date
	* @return result -boolean
	* @throws DataAccessException
	*/
	public boolean isExistByMonitorIdAndCreateDate(final int monitorId,final Date createDate) throws DataAccessException;
	
	/**
	* update ocap by data key and chart type .
	* @param dataKey -int
	* @param ocap -String
	* @param chartType -String
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateOcap(final int dataKey, final String ocap, final String chartType) throws DataAccessException;
	
	/**
	 * 
	 * @param chartKey
	 * @param ocap
	 * @return
	 * @throws DataAccessException
	 */
	public int updateOcapByHold(final int chartKey, final String ocap) throws DataAccessException;

	/**
	 * get continuous datas by monitor id and chart type and last data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByMonitorIdAndChartTypeAndLastDataId(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
	 * get continuous datas by monitor id and chart type and last data id and next data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByMonitorIdAndChartTypeAndLastDataIdAndNextDataId(final int monitorId, final String chartType, final int lastDataId, final int nextDataId) throws DataAccessException;
	
	/**
	 * get last fifteen continuous datas by monitor id and chart type and last data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public LinkedList<ContinuousData> getLastFifteenContinuousDatasByChartTypeAndMonitorId(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
	 * get continuous datas by latest points with current revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param latestPoints -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByLatestPointsWithCurrentRevision(final int monitorId, final String chartType, final int lastDataId, final int latestPoints) throws DataAccessException;
	
	/**
	 * get continuous datas by latest points with old revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @param latestPoints -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByLatestPointsWithOldRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId, final int latestPoints) throws DataAccessException;
	
	/**
	 * get discrete datas by date with current revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param startDate -Date
	 * @param endDate -Date
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByDateWithCurrentRevision(final int monitorId, final String chartType, final int lastDataId,
			final Date startDate, final Date endDate) throws DataAccessException ;
	
	/**
	 * get discrete datas by date with old revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @param startDate -Date
	 * @param endDate -Date
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getContinuousDatasByDateWithOldRevision(final int monitorId, final String chartType, final int lastDataId,
			final int nextDataId, final Date startDate, final Date endDate) throws DataAccessException;
	
	/**
	* get max revision continuous datas by monitor id and chart type.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @throws DataAccessException
	*/
	public List<ContinuousData> getMaxRevisionContinuousDatasByMonitorIdAndChartType(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
     * delete continuous data by data id.
     * @param dataId -int
     * @return result -int
	 * @throws DataAccessException
     */
	public int deleteContinuousDataByDataId(final int dataId) throws DataAccessException;
	
	/**
	 * get current page continuous datas by chart type and current revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param limit -int
	 * @param start -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getCurrentPageContinuousDatasByChartTypeAndCurrentRevision(final int monitorId, final String chartType, final int lastDataId, final int limit , final int start) throws DataAccessException;
	
	/**
	 * get current page continuous datas by chart type and old revision.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @param limit -int
	 * @param start -int
	 * @return List<ContinuousData> - continuousDataList
	 * @throws DataAccessException
	 */
	public List<ContinuousData> getCurrentPageContinuousDatasByChartTypeAndOldRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId, final int limit , final int start) throws DataAccessException;
	
	/**
	 * get count with continuous datas by monitor id and chart type and last data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @return count - int
	 * @throws DataAccessException
	 */
	public int getCountContinuousDatasByChartTypeAndCurrentRevision(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
	 * get count continuous datas by monitor id and chart type and last data id and next data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @return count - int
	 * @throws DataAccessException
	 */
	public int getCountContinuousDatasByChartTypeAndOldRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId) throws DataAccessException;

	public int deleteContinousDetailDataByDataId(int dataId);

	public int deleteContinousDataByDataId(int dataId);

	public List<ContinuousData> getLastContinuousDataByMonitorId2(int monitorId);

	public long getADateTimeFromActivityByDataKey(int dataKey);
	
}
